package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
	"strconv"
	"strings"
)

func main() {
	EnsureState("enabled")
	r := gin.Default()
	r.GET("/", func(c *gin.Context) {
		c.String(http.StatusOK, "hello word")
	})
	r.GET("/test", func(c *gin.Context) {
		c.JSON(http.StatusOK,  gin.H{
			"data": "hello test",
		})
	})
	r.GET("/api/blog/detail/:id", func(c *gin.Context) {
		idStr := c.Param("id")
		fmt.Println("id:",idStr)
		id, _ := strconv.Atoi(idStr)
		c.JSON(http.StatusOK,  gin.H{
			"data": id,
			"code": 20000,
		})
	})
	r.PUT("/xxxput")
	//监听端口默认为8080
	r.Run(":8000")
}

const (
	DRAFT    = "DRAFT"
	ENABLED  = "ENABLED"
	DISABLED = "DISABLED"
	DEL      = "DEL"
)

var allowedStates = map[string]bool{
	DRAFT:    true,
	ENABLED:  true,
	DISABLED: true,
	DEL:      true,
}

func EnsureState(state string) (string, bool) {
	state = strings.ToUpper(strings.TrimSpace(state))
	val, ok := allowedStates[state]
	fmt.Println("val:",val)
	fmt.Println("ok:",ok)
	fmt.Println("state:",state)
	return state, ok
}